package com.rede.didiok.admin.restapi.admin;


import java.util.List;

import javax.annotation.Resource;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.rede.didiok.admin.annotion.AuthorityVerify.AuthorityVerify;
import com.rede.didiok.admin.annotion.OperationLogger.OperationLogger;
import com.rede.didiok.common.annotion.AvoidRepeatableCommit.AvoidRepeatableCommit;
import com.rede.didiok.common.dto.community.UserMomentTopicDto;
import com.rede.didiok.common.exception.ThrowableUtils;
import com.rede.didiok.common.feign.CommunityFeignClient;
import com.rede.didiok.common.validator.group.Delete;
import com.rede.didiok.common.validator.group.GetList;
import com.rede.didiok.common.validator.group.Insert;
import com.rede.didiok.common.validator.group.Update;

/**
 * 用户动态话题表 RestApi
 *
 * @author 陌溪
 * @date 2021年12月26日08:25:36
 */
@Api(value = "用户动态话题相关接口", tags = {"用户动态话题相关接口"})
@RestController
@RequestMapping("/admin/userMomentTopic")
@Slf4j
public class UserMomentTopicRestApi {

    @Resource
    private CommunityFeignClient communityFeignClient;

    @AuthorityVerify
    @ApiOperation(value = "获取用户动态话题列表", notes = "获取用户动态话题列表", response = String.class)
    @PostMapping("/getList")
    public String getList(@Validated({GetList.class}) @RequestBody UserMomentTopicDto userMomentTopicDto, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("获取用户动态话题列表");
        return communityFeignClient.getUserMomentTopicPageList(userMomentTopicDto);
    }

    @AvoidRepeatableCommit
    @AuthorityVerify
    @OperationLogger(value = "增加用户动态话题")
    @ApiOperation(value = "增加用户动态话题", notes = "增加用户动态话题", response = String.class)
    @PostMapping("/add")
    public String add(@Validated({Insert.class}) @RequestBody UserMomentTopicDto userMomentTopicDto, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("增加用户动态话题");
        return communityFeignClient.addUserMomentTopic(userMomentTopicDto);
    }

    @AuthorityVerify
    @OperationLogger(value = "编辑用户动态话题")
    @ApiOperation(value = "编辑用户动态话题", notes = "编辑用户动态话题", response = String.class)
    @PostMapping("/edit")
    public String edit(@Validated({Update.class}) @RequestBody UserMomentTopicDto userMomentTopicDto, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("编辑用户动态话题");
        return communityFeignClient.editUserMomentTopic(userMomentTopicDto);
    }

    @AuthorityVerify
    @OperationLogger(value = "批量删除用户动态话题")
    @ApiOperation(value = "批量删除用户动态话题", notes = "批量删除用户动态话题", response = String.class)
    @PostMapping("/deleteBatch")
    public String delete(@Validated({Delete.class}) @RequestBody List<UserMomentTopicDto> userMomentTopicDtoList, BindingResult result) {

        // 参数校验
        ThrowableUtils.checkParamArgument(result);
        log.info("批量删除用户动态话题");
        return communityFeignClient.deleteBatchUserMomentTopic(userMomentTopicDtoList);
    }
}

